package contract.jvm.instructions;

import contract.jvm.Frame;
import contract.jvm.Jvm;
import contract.jvm.Reference;
import org.objectweb.asm.tree.FieldInsnNode;

public class Putfield {

    /**
     * 对象字段赋值
     */
    public static void putfield(Jvm jvm) {
        Frame frame = jvm.jvmStack.lastElement();
        FieldInsnNode fieldInsnNode = (FieldInsnNode) jvm.pc.currentInsnNode;
        String fieldName = fieldInsnNode.name;

        Object value = frame.operandStack.pop();
        Reference reference = (Reference) frame.operandStack.pop();
        jvm.heap.putField(reference, fieldName, value);
    }

}
